from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-05-12 14:05:14.578316
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 12, May, 2022
Time: 14:05:21
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.2582
Nobs: 654.000 HQIC: -49.6359
Log likelihood: 8047.30 FPE: 2.18530e-22
AIC: -49.8751 Det(Omega_mle): 1.90633e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.322653 0.061133 5.278 0.000
L1.Burgenland 0.104842 0.039007 2.688 0.007
L1.Kärnten -0.109838 0.020450 -5.371 0.000
L1.Niederösterreich 0.193755 0.081392 2.381 0.017
L1.Oberösterreich 0.123365 0.080347 1.535 0.125
L1.Salzburg 0.257089 0.041427 6.206 0.000
L1.Steiermark 0.044300 0.054383 0.815 0.415
L1.Tirol 0.103156 0.043869 2.351 0.019
L1.Vorarlberg -0.062974 0.038816 -1.622 0.105
L1.Wien 0.029274 0.071141 0.411 0.681
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.050401 0.130534 0.386 0.699
L1.Burgenland -0.032650 0.083289 -0.392 0.695
L1.Kärnten 0.040418 0.043666 0.926 0.355
L1.Niederösterreich -0.188772 0.173794 -1.086 0.277
L1.Oberösterreich 0.449809 0.171561 2.622 0.009
L1.Salzburg 0.284644 0.088457 3.218 0.001
L1.Steiermark 0.107977 0.116121 0.930 0.352
L1.Tirol 0.312333 0.093672 3.334 0.001
L1.Vorarlberg 0.022081 0.082881 0.266 0.790
L1.Wien -0.038046 0.151905 -0.250 0.802
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189040 0.031358 6.029 0.000
L1.Burgenland 0.089698 0.020008 4.483 0.000
L1.Kärnten -0.007922 0.010490 -0.755 0.450
L1.Niederösterreich 0.250760 0.041750 6.006 0.000
L1.Oberösterreich 0.155483 0.041213 3.773 0.000
L1.Salzburg 0.042613 0.021250 2.005 0.045
L1.Steiermark 0.025321 0.027895 0.908 0.364
L1.Tirol 0.085909 0.022502 3.818 0.000
L1.Vorarlberg 0.054227 0.019910 2.724 0.006
L1.Wien 0.116203 0.036491 3.184 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111959 0.031492 3.555 0.000
L1.Burgenland 0.045859 0.020094 2.282 0.022
L1.Kärnten -0.014134 0.010535 -1.342 0.180
L1.Niederösterreich 0.181208 0.041929 4.322 0.000
L1.Oberösterreich 0.328415 0.041390 7.935 0.000
L1.Salzburg 0.101490 0.021341 4.756 0.000
L1.Steiermark 0.109973 0.028015 3.926 0.000
L1.Tirol 0.096522 0.022599 4.271 0.000
L1.Vorarlberg 0.059975 0.019996 2.999 0.003
L1.Wien -0.022111 0.036648 -0.603 0.546
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.115465 0.058584 1.971 0.049
L1.Burgenland -0.043899 0.037380 -1.174 0.240
L1.Kärnten -0.046434 0.019597 -2.369 0.018
L1.Niederösterreich 0.140595 0.077998 1.803 0.071
L1.Oberösterreich 0.160845 0.076996 2.089 0.037
L1.Salzburg 0.282035 0.039699 7.104 0.000
L1.Steiermark 0.055930 0.052115 1.073 0.283
L1.Tirol 0.166042 0.042040 3.950 0.000
L1.Vorarlberg 0.095943 0.037197 2.579 0.010
L1.Wien 0.075770 0.068175 1.111 0.266
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.061249 0.046209 1.325 0.185
L1.Burgenland 0.031419 0.029485 1.066 0.287
L1.Kärnten 0.051276 0.015458 3.317 0.001
L1.Niederösterreich 0.204511 0.061523 3.324 0.001
L1.Oberösterreich 0.317666 0.060733 5.231 0.000
L1.Salzburg 0.041150 0.031314 1.314 0.189
L1.Steiermark 0.007112 0.041107 0.173 0.863
L1.Tirol 0.131769 0.033160 3.974 0.000
L1.Vorarlberg 0.065532 0.029340 2.234 0.026
L1.Wien 0.089167 0.053774 1.658 0.097
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.175849 0.055457 3.171 0.002
L1.Burgenland 0.004753 0.035385 0.134 0.893
L1.Kärnten -0.065364 0.018551 -3.523 0.000
L1.Niederösterreich -0.099307 0.073836 -1.345 0.179
L1.Oberösterreich 0.204198 0.072887 2.802 0.005
L1.Salzburg 0.054235 0.037581 1.443 0.149
L1.Steiermark 0.242593 0.049334 4.917 0.000
L1.Tirol 0.501685 0.039796 12.606 0.000
L1.Vorarlberg 0.058396 0.035212 1.658 0.097
L1.Wien -0.074361 0.064536 -1.152 0.249
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.147214 0.061485 2.394 0.017
L1.Burgenland 0.004538 0.039232 0.116 0.908
L1.Kärnten 0.060403 0.020568 2.937 0.003
L1.Niederösterreich 0.182119 0.081862 2.225 0.026
L1.Oberösterreich -0.056979 0.080810 -0.705 0.481
L1.Salzburg 0.205755 0.041666 4.938 0.000
L1.Steiermark 0.134743 0.054696 2.463 0.014
L1.Tirol 0.068410 0.044122 1.550 0.121
L1.Vorarlberg 0.143590 0.039040 3.678 0.000
L1.Wien 0.111955 0.071552 1.565 0.118
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.376341 0.036194 10.398 0.000
L1.Burgenland -0.000893 0.023094 -0.039 0.969
L1.Kärnten -0.021814 0.012107 -1.802 0.072
L1.Niederösterreich 0.212191 0.048188 4.403 0.000
L1.Oberösterreich 0.228144 0.047569 4.796 0.000
L1.Salzburg 0.038579 0.024527 1.573 0.116
L1.Steiermark -0.014728 0.032197 -0.457 0.647
L1.Tirol 0.094344 0.025973 3.632 0.000
L1.Vorarlberg 0.053984 0.022981 2.349 0.019
L1.Wien 0.035846 0.042119 0.851 0.395
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036375 0.114632 0.173373 0.142206 0.100126 0.083933 0.039981 0.210385
Kärnten 0.036375 1.000000 -0.020259 0.134695 0.052278 0.089793 0.440555 -0.060337 0.093173
Niederösterreich 0.114632 -0.020259 1.000000 0.324487 0.127789 0.285208 0.072921 0.162031 0.296773
Oberösterreich 0.173373 0.134695 0.324487 1.000000 0.220713 0.309533 0.167231 0.150804 0.251424
Salzburg 0.142206 0.052278 0.127789 0.220713 1.000000 0.129815 0.097475 0.115198 0.129911
Steiermark 0.100126 0.089793 0.285208 0.309533 0.129815 1.000000 0.138437 0.117996 0.049885
Tirol 0.083933 0.440555 0.072921 0.167231 0.097475 0.138437 1.000000 0.069581 0.146583
Vorarlberg 0.039981 -0.060337 0.162031 0.150804 0.115198 0.117996 0.069581 1.000000 0.007350
Wien 0.210385 0.093173 0.296773 0.251424 0.129911 0.049885 0.146583 0.007350 1.000000